var https = require('https');
var fs = require('fs');

// var haveCert = false;
var haveCert = true;
var options = {
    hostname: '127.0.0.1',
    port: 3000,
    path: '/',
    method: 'GET',
    rejectUnauthorized: true
};

if (haveCert) {
    options.rejectUnauthorized = true;
    options.key = fs.readFileSync('./keys/client-key.pem')
    options.cert = fs.readFileSync('./keys/client-cert.pem')
    options.ca = [fs.readFileSync('./keys/ca-cert.pem')]
}

options.agent = new https.Agent(options);
var req = https.request(options, function (res) {
    console.log("statusCode: ", res.statusCode);
    console.log("headers: ", res.headers);
    res.setEncoding('utf-8');
    res.on('data', function (d) {
        console.log(d);
    })
});

req.end();

req.on('error', function (e) {
    console.log(e);
})